#include "../includes/led.h"
#include "../includes/processor.h"

void led_init(){
	//set up a port for output
	int i = 0;
	TRISC &= 0b11111011;
	//PORTC &= 0b11111011;
	PORTC |= 0b00000100;
	for(i = 0; i < 30000;i++);
	
	
	//init the pwn
	pwm_init();
}

void pwm_init(){
	PR2 = 0xFF;
	T2CON = 0b00000101;
	CCP1CON = 0b00111100;
	CCPR1L = 0;
}


void set_duty_cycle(unsigned int num){
	if( num >= 0 && num <= 255 )
		CCPR1L = num;
	else
		CCPR1L = 255;
}

int get_duty_cycle(){
	return CCPR1L;
}

void switch_strength(){
	CCPR1L = 255 - CCPR1L;
}

void inc_duty_cycle(){
	CCPR1L = (CCPR1L+1)%256;
}

void dec_duty_cycle(){
	CCPR1L = 255-((CCPR1L+1)%256);
}

void double_inc_duty_cycle(){
	CCPR1L = (CCPR1L+4)%256;
}	